package com.example.luyi.omgandroid;

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


public class ListActivity extends ActionBarActivity {

    private ListView listView = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list);

        listView = (ListView)findViewById(R.id.list_View);
        List<HashMap<String,String>> myList = new ArrayList<HashMap<String, String>>();
        for (int i = 0;i < 10; i++){
            HashMap<String,String> map = new HashMap<String, String>();
            map.put("title","This is a title");
            map.put("detail","detail");
            myList.add(map);
        }

        SimpleAdapter adapter = new SimpleAdapter(this,
                myList,
                R.layout.activity_listitem,
                new String[]{"title","detail"},
                new  int[]{R.id.list_item_title,R.id.list_item_detail});
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position){
                    case 0:
                        Intent intent = new Intent(ListActivity.this,DpTpActivity.class);
                        startActivity(intent);
                        break;
                    case 2:
                        break;
                    default:
                        break;
                }
            }
        });
    }
}
